/**
 * This class is designed to be used in both website and android.
 * <p/>
 * zhaoxu @ 2012-05-22 12:06
 * <p/>
 */
package com.threeti.mecool.core.domain.model.plan.pojo;

import org.codehaus.jackson.annotate.JsonBackReference;
import org.codehaus.jackson.annotate.JsonIgnore;

public class Step {
	private Long id;
	private Integer version;
	private Task task;
	private int optional;
	private Job job;
	private Step nextStep;
	private transient Long nextStepId;
	private int stepsOrder;

	@JsonBackReference
	public Job getJob() {
		return job;
	}

	public void setJob(Job job) {
		this.job = job;
	}

	public int getOptional() {
		return optional;
	}

	@JsonIgnore
	public boolean isOptional() {
		return optional != 0;
	}

	public void setOptional(boolean val) {
		optional = val ? 1 : 0;
	}

	public void setOptional(int optional) {
		this.optional = optional;
	}

	public Task getTask() {
		return task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@JsonIgnore
	public Step getNextStep() {
		if (nextStep == null && nextStepId != null) {
			nextStep = job.findStepById(nextStepId);
		}
		return nextStep;
	}

	public void setNextStep(Step nextStep) {
		this.nextStep = nextStep;
	}

	public Long getNextStepId() {
		if (nextStepId == null && nextStep != null) {
			nextStepId = nextStep.getId();
		}
		return nextStepId;
	}

	public void setNextStepId(Long val) {
		nextStepId = val;
	}

	public Integer getVersion() {
		return version;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	public int getStepsOrder() {
		return stepsOrder;
	}

	public void setStepsOrder(int stepsOrder) {
		this.stepsOrder = stepsOrder;
	}

}
